﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

namespace PRE.Catalog
{
    public partial class FrmDanhSachTheDocGiaBiKhoa : DevExpress.XtraEditors.XtraForm
    {
        #region Variable
        DAL.EntitiesDAL.TheDocGiaDAL _dal = new DAL.EntitiesDAL.TheDocGiaDAL();
        BLL.EntitiesBLL.TheDocGiaBLL _bll = new BLL.EntitiesBLL.TheDocGiaBLL();

        DataTable _dt = new DataTable();
        #endregion

        #region Inits

        public FrmDanhSachTheDocGiaBiKhoa()
        {
            InitializeComponent();
        }

        #endregion

        #region Load du lieu
        private void FrmDanhSachSachMuon_Load(object sender, EventArgs e)
       {
           GetData();
       }
        #endregion

        #region Thoát
        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
       #endregion

        #region Làm tươi
        private void btn_Refresh_Click(object sender, EventArgs e)
        {
            FrmDanhSachSachMuon_Load(null, null);
        }
       #endregion

        #region In dữ liệu
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (_dt.Select("IsCheck = True").Length == 0)
                {
                    XtraMessageBox.Show("Chưa chọn đọc giả cần in", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                string _NgayKy = "TP.Cần Thơ, ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year;

                if (gridView_TheDocGia.DataRowCount > 0)
                {
                    DataTable dt = gridView_TheDocGia.GetDataRow(0).Table.Clone();

                    for (int i = 0; i < gridView_TheDocGia.DataRowCount; i++)
                    {
                        if (gridView_TheDocGia.GetDataRow(i)["IsCheck"].ToString() == "True")
                            dt.ImportRow(gridView_TheDocGia.GetDataRow(i));
                    }

                    Reports.FrmReportView frm = new Reports.FrmReportView();
                    frm._load_XtraDanhSachDocGiaBiKhoaThe(dt, _NgayKy);
                    frm.Show();
                }
            }
            catch { }
        }
        #endregion

        #region Chọn tất cả
        private void checkEdit_All_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gridView_TheDocGia.DataRowCount; i++)
            {
                gridView_TheDocGia.GetDataRow(i)["IsCheck"] = checkEdit_All.Checked;
            }
        }
       #endregion

       #region GetData
       private void GetData()
       {
           _dt = _dal.Select_TheDocGiaBiKhoa();

           try
           {
               if (_dt != null)
               {
                   _dt.Columns.Add("IsCheck", typeof(bool));

                   foreach (DataRow dr in _dt.Rows)
                       dr["IsCheck"] = false;

                   gridControl_TheDocGia.DataSource = _dt;
                   
                   AppGridView.ReadOnlyColumn(gridView_TheDocGia,
                     new string[] { "MADOCGIA", "HODOCGIA", "NGAYSINH", "GIOITINH", "SCMND", "DIACHI", "DIENTHOAI"
                           , "NGHENGHIEP", "NOICONGTAC", "NGAYBATDAU", "NGAYHETHAN", "MALOAIDG", "DOITUONG" });
                   AppGridView.SummaryField(gridView_TheDocGia, "MADOCGIA", "Tổng = {0:#,0}", DevExpress.Data.SummaryItemType.Count);

                   gridView_TheDocGia.Columns["MALOAIDG"].Visible = false;
                   gridView_TheDocGia.OptionsView.EnableAppearanceEvenRow = true;
                   gridView_TheDocGia.OptionsView.ColumnAutoWidth = true;
               }
           }
           catch (Exception ex)
           {

               XtraMessageBox.Show("Lỗi! Không load được dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
       }
        #endregion 










    }
}